export const loadScript = function (url) {
  return new Promise(function (resolve, reject) {
    const script = document.createElement('script')
    script.type = 'text/javascript'
    script.charset = 'utf-8'
    script.async = true
    script.timeout = 12000
    if (script.readyState) {
      // IE
      script.onreadystatechange = function () {
        if (script.readyState === 'loaded' || script.readyState === 'complete') {
          script.onreadystatechange = null
          resolve()
        }
      }
    } else {
      // Others: Firefox, Safari, Chrome, and Opera
      script.onload = resolve
    }
    script.onerror = reject
    script.src = url
    document.body.appendChild(script)
  })
}
